package com.example.shop.adapter;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.shop.R;
import com.example.shop.entity.HomeEntity;
import com.example.sjlibrary.adapter.SimplePagerAdapter;
import com.example.sjlibrary.base.BaseActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import java.util.List;

/**
 * Created by Administrator on 2016/3/11.
 */
public class VpBannerFragHomeItemAdapter extends SimplePagerAdapter {
    private List<HomeEntity.HomeBannerEntity> mHomeBannerEntities;
    private BaseActivity mSCBaseActivity;
    private LayoutInflater mLayoutInflater;
   	private DisplayImageOptions options;
    public int mPicShowPos;
    public int mPicNums;
    public VpBannerFragHomeItemAdapter(List<HomeEntity.HomeBannerEntity> homeBannerEntities, BaseActivity SCBaseActivity) {
        mHomeBannerEntities = homeBannerEntities;
        mSCBaseActivity = SCBaseActivity;
        mLayoutInflater=mSCBaseActivity.mLayoutInflater;
        options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.product_loading)
                .showImageOnFail(R.drawable.product_loading)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new FadeInBitmapDisplayer(300))
                .build();
        mPicNums=homeBannerEntities.size();
    }

    @Override
    public View initView(ViewGroup container, int position) {
        ImageView view= (ImageView) mLayoutInflater.inflate(R.layout.vp_banner_frag_home_item,container,false);
        mPicShowPos=position%mHomeBannerEntities.size();
        ImageLoader.getInstance().displayImage(mHomeBannerEntities.get(mPicShowPos).getPic(),view,options);
        return view;
    }
    @Override
    public int getCount() {
        return 100000;
    }
}
